﻿/*----------------------------------------------------------------
    // Copyright (C) 2009 江苏华招网
    // 版权所有。 
    // 作者：吕海乐 
    //
    // 文件名：BidProductAbandon.cs
    // 文件功能描述：采购产品管理：撤废和恢复采购产品
    // 创建标识：吕海乐2009-03-19
    //
    // 修改标识：
    // 修改描述：
    //
    // 修改标识：
    // 修改描述：
    //
    // 审核人：
// 审核时间：
// 审核说明：
 //----------------------------------------------------------------*/
using System;
using System.Collections;
using System.Configuration;
using System.Data;

using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

using System.Collections.Generic;
using HZ.DrugTrade.Web;
using HZ.DrugTrade.Model;
using HZ.DrugTrade.Model.Enum;
using HZ.DrugTrade.IBLL;
using HZ.DrugTrade.BLLFactory;

namespace HZ.DrugTrade.Web.Admin
{
    public partial class BidProductAbandon : BasePage
    {
        IBLL_ProcurementBasic ipb = Factory.BLL_ProcurementBasic();
        public BidProductAbandon()
        {
            this.ModuleNo = Module.采购产品管理.ToString();
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            //绑定所有采购产品
            if (!this.IsPostBack)
            {
                try
                {
               
                }
                catch(Exception ex)
                {
                    PageError(ex.Message,"");
                }

            }
            setBind();
        }

        protected void AspNetPager1_OnPageChanged(object sender, EventArgs e)
        {
            setBind();
        }

        protected void btnQuery_Click(object sender, EventArgs e)
        {
            AspNetPager1.CurrentPageIndex = 1;
            setBind();
        }

        private void setBind()
        {
            //获取查询条件
            Model.Query.ProcureCatalog procureCatalog = new HZ.DrugTrade.Model.Query.ProcureCatalog();
            procureCatalog.CompanyName_SC = txtProduceCompany_SC.Text.Trim();
            procureCatalog.GoodsName = txtGoodsName.Text.Trim();
            procureCatalog.Material = txtMaterial.Text.Trim();
            procureCatalog.Outlookc = txtOutLook.Text.Trim();
            procureCatalog.ProjectName = txtProject.Text.Trim();
            procureCatalog.GoodsName = txtGoodsName.Text.Trim();
            procureCatalog.PackUnit = txtPackUnit.Text.Trim();

            if (!string.IsNullOrEmpty(txtProcureStartTime.Text.Trim()))
            {
                procureCatalog.ProcureStartTime = Convert.ToDateTime(txtProcureStartTime.Text.Trim());
            }
            if (!string.IsNullOrEmpty(txtProcureEndTime.Text.Trim()))
            {
                procureCatalog.ProcureEndTime =Convert.ToDateTime(txtProcureEndTime.Text.Trim());
            }
            procureCatalog.CompanyName_TB = txtCompany_TB.Text.Trim();
            procureCatalog.SortFields = " GoodsName asc";

            //调用方法，执行查询，分页显示产品信息
            AspNetPager1.PageSize =Constants.GRIDVIEW_PAGE_SIZE;
            int totalCount = 0;

            try
            {

                IList<Model.View.ProcureCatalog> procureCatalogList = ipb.GetProcureCatalogByWhere(procureCatalog, AspNetPager1.CurrentPageIndex, AspNetPager1.PageSize, out totalCount);
                AspNetPager1.RecordCount = totalCount;
                gvwProduceCatalog.DataSource = procureCatalogList;
                gvwProduceCatalog.DataBind();
            }
            catch (Exception ex)
            {
                PageError(ex.Message, "");
            }
        }

        /// <summary>
        /// 撤废
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnAbandon_Click(object sender, EventArgs e)
        {
           string ids = Request["checkbox1"];
           
            if (!string.IsNullOrEmpty(ids))
            {
                string[] arraryIds = ids.Split(',');               
                foreach (string Item in arraryIds)
                {
                    Model.View.ProcureCatalog tmpProcureCatalog = ipb.GetProcureCatalogByID(Item);
                    if (Convert.ToBoolean(tmpProcureCatalog.IsUsing))
                    {
                        ProcureCatalog aProcureCatalog = new ProcureCatalog();
                        aProcureCatalog.IsUsing = false;
                        aProcureCatalog.ProcureCatalogID = tmpProcureCatalog.ProcureCatalogID;
                        int nSuccess = ipb.UpdateProcureCatalog_IsUsing(aProcureCatalog);
                        if (nSuccess == 0)
                        {
                            PageError("数据操作失败！", "");
                        }
                    }
                }               
            }
            setBind();
        }

        /// <summary>
        /// 恢复
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnRecover_Click(object sender, EventArgs e)
        {
            string ids = Request["checkbox1"];

            if (!string.IsNullOrEmpty(ids))
            {
                string[] arraryIds = ids.Split(',');
                foreach (string Item in arraryIds)
                {
                    Model.View.ProcureCatalog tmpProcureCatalog = ipb.GetProcureCatalogByID(Item);
                    if (!Convert.ToBoolean(tmpProcureCatalog.IsUsing))
                    {
                        ProcureCatalog aProcureCatalog = new ProcureCatalog();
                        aProcureCatalog.IsUsing = true;
                        aProcureCatalog.ProcureCatalogID = tmpProcureCatalog.ProcureCatalogID;
                        int nSuccess = ipb.UpdateProcureCatalog_IsUsing(aProcureCatalog);
                        if (nSuccess == 0)
                        {
                            PageError("数据操作失败！", "");
                        }
                    }
                }
            }
            setBind();
        }
    }
}
